package com.atguigu.mySmartCampus.Service.impl;

import com.atguigu.mySmartCampus.mapper.ClazzMapper;
import com.atguigu.mySmartCampus.Service.ClazzService;
import com.atguigu.mySmartCampus.entity.Clazz;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {
    @Override
    public Clazz getClazzById(String id) {

        Clazz clazz = baseMapper.selectById(id);
        return clazz;
    }

    @Override
    public List<Clazz> selectClazz() {


        return baseMapper.selectList(null);
    }

    @Override
    public IPage<Clazz> getClazzsByOpr(Page<Clazz> clazzPage, Clazz clazz) {
        QueryWrapper qw = new QueryWrapper();
        String clazzName = clazz.getName();
        if (!StringUtils.isEmpty(clazzName)){
            qw.like("name",clazzName);
        }
        String gradeName = clazz.getGradeName();
        if (!StringUtils.isEmpty(gradeName)){
            qw.like("grade_name",gradeName);
        }
        Page page = baseMapper.selectPage(clazzPage, qw);
        return page;
    }
}
